<template>
    <div id="queryreplenish" v-loading="loading">
        <v-tableTitle :btnConfig="btnConfig"
                      :tableSelectData="tableSelectData"
                      :title="$t('ex.checkreplenish')" @exportFile="exportFile"></v-tableTitle>
        <v-table
                :hasEdit="false"
                :pageSize="pageSize"
                :page="page"
                :tableConfig="tableConfig"
                :tableData="tableData"
                :total="total"
                @findData="getTableData"
                @getTableData="getTableData"
                @searhData="searhData"
                @selectData="selectData"
                @upData="getTableData"
                ref="table"
        ></v-table>
    </div>
</template>

<script type="text/ecmascript-6">
    import tableTitle from "commons/TableTitle";
    import table from "commons/Table";
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        name: "queryreplenish",
        mixins: [baseMixin],
        data() {
            return {
                loading: false,
                tableConfig: [
                    {
                        label: this.$t('config.area'),
                        prop: "putawayzone",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.replenishkey'),
                        prop: "replenishkey",
                        input: "input"
                    },
                    {
                        label: this.$t('config.toLoc'),
                        prop: "toloc",
                        input: "input",
                    },
                    {
                        label: this.$t('common.status'),
                        prop: "status",
                        input: "select",
                        options: [
                            {code: "0", description: this.$t('code.status1')},
                            {code: "3", description: this.$t('code.status2')},
                            {code: "9", description: this.$t('code.status3')},
                        ]
                    },
                    {
                        label: this.$t('config.shipper'),
                        prop: "storerkey",
                        input: "input",
                    },
                    {
                        label: this.$t('config.sku'),
                        prop: "sku",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.currentqty'),
                        prop: "qty",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.qtyavailable'),
                        prop: "availableqty",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.rtxrpqty'),
                        prop: "replenishmentqty",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.qtylocationminimum'),
                        prop: "qtylocationminimum",
                        input: "input",
                    },
                    {
                        label: this.$t('ex.qtylocationlimit'),
                        prop: "qtylocationlimit",
                        input: "input",
                    },
                   /* {
                        label: this.$t('common.locabcinclude01'),
                        prop: "locabc",
                        input: "input",
                    },
                    {
                        label: this.$t('outbound.skuabcinclude01'),
                        prop: "skuabc",
                        input: "input",
                    },*/
                    {
                        label: this.$t('ex.taskgroup'),
                        prop: "taskgroup",
                        input: "input",
                    }
                ],
                tableData: [],
              page: 1,
                pageSize: 10,
                total: 0,
                tableSelectData: [],
                tableSearhData: {},
            };
        },
        computed: {
            btnConfig() {
                return [
                    {label: this.$t('common.export'), invalid: "exportFile"},
                ]
            }
        },
        created() {
        },
        methods: {
            async exportFile() {
                if (Object.keys(this.tableSearhData).length !== 0) {
                    try {
                        let res = await this.$api.post(`/exportReplenish`, this.tableSearhData, {responseType: 'blob'});
                        if (window.navigator.msSaveBlob) {
                            var blobObject = new Blob([res.data]);
                            window.navigator.msSaveBlob(blobObject, this.$t('ex.replenish') + '.xls');
                        } else {
                            var blob = new Blob([res.data], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8'});
                            var filename = this.$t('ex.replenish') + '.xls';
                            var downloadElement = document.createElement('a');
                            var href = window.URL.createObjectURL(blob); //创建下载的链接
                            downloadElement.style.display = 'none';
                            downloadElement.href = href;
                            downloadElement.download = filename; //下载后文件名
                            document.body.appendChild(downloadElement);
                            downloadElement.click(); //点击下载
                            document.body.removeChild(downloadElement); //下载完成移除元素
                            window.URL.revokeObjectURL(href); //释放掉blob对象
                        }
                    } catch (e) {
                        this.$message.error(e);
                    }
                } else {
                    this.$message.error(this.$t('msg.msg29'));
                }
            },
            //选中的内容
            selectData(data) {
                this.tableSelectData = data;
            },
            async getTableData(page, data) {
                try {
                    this.loading = true;
                    let res = await this.$api.post(`/queryReplenishList/${page}`, data);
                    
                        this.tableData = res.page.list;
                      this.page = res.page.curpage;
                        this.pageSize = res.page.pageSize;
                        this.total = res.page.total;
                    
                } catch (e) {
                    this.$message.error(e);
                } finally {
                    this.loading = false;
                }
            },
            //搜索的值
            searhData(data, up) {
                if (!up) {
                    this.tableSearhData = data;
                } else {
                    this.tableSearhData = data;
                    this.getTableData(1, this.tableSearhData);
                }
            },
        },
        mounted() {
            this.$store.commit("setSkip", {});
            this.$store.commit("setNewFlag", false);
            this.$store.commit("setRouteData", {});
            this.getTableData(1, {});
        },
        watch: {},
        components: {
            "v-tableTitle": tableTitle,
            "v-table": table,
        }
    };
</script>

<style scoped>
    #queryreplenish {
        width: 100%;
        height: 99%;
        padding-top: 6px;
    }
</style>
